package com.sskj.lib.util;

import android.app.Activity;

import com.alibaba.android.arouter.launcher.ARouter;
import com.sskj.common.base.App;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.R;
import com.sskj.lib.RConfig;
import com.sskj.lib.bean.UserData;

public class AppCircleCheckUtil {


    /**
     * 检测是否登录，没有登录直接跳转登录界面
     *
     * @param activity
     * @param userData
     * @return
     */
    public static boolean checkLogin(Activity activity, UserData userData) {
        if (userData == null) {
            TipUtil.getSureTip(activity, ""/*App.INSTANCE.getString(R.string.liblogoutProviderImpl1)*/, App.INSTANCE.getString(R.string.libappCircleCheckUtil2), App.INSTANCE.getString(R.string.libappCircleCheckUtil3), () -> {
                ARouter.getInstance().build(RConfig.LOGIN_LOGIN).navigation();
                activity.overridePendingTransition(R.anim.lib_anim_in, R.anim.lib_anim_out);
            });
            return false;
        }
        return true;
    }


    /**
     * 验证资金密码
     *
     * @param userData
     * @return
     */
    public static boolean checkTradePwd(Activity activity, UserData userData) {
        if (userData.getTradePswdStatus() == 1) {
            return true;
        } else {
            TipUtil.getSureTip(activity, App.INSTANCE.getString(R.string.libappCircleCheckUtil4), App.INSTANCE.getString(R.string.libappCircleCheckUtil5), App.INSTANCE.getString(R.string.libappCircleCheckUtil6), () -> {
                ARouter.getInstance().build(RConfig.MINE_SET_FUND_PWD)
                        .withString("mobile", userData.getTel())
                        .withInt("type", userData.getTradePswdStatus()).navigation();

            });
            return false;
        }
    }


    /**
     * 验证商家
     *
     * @param userData
     * @return
     */
    public static boolean checkShop(Activity activity, UserData userData) {
        if (userData.getShopAuthenticationStatus() == 1 || userData.getShopAuthenticationStatus() == 5) {  // 不是商家

            BottomSheetUtil.showShopCheck(activity, "", () -> {
                ARouter.getInstance().build(RConfig.MINE_SECURITY_CENTER).navigation();
            }).show();
            return false;
        }
        if (userData.getShopAuthenticationStatus() == 2) {
            ToastUtil.showShort(App.INSTANCE.getString(R.string.libappCircleCheckUtil7));
            return false;
        }

        if (userData.getShopAuthenticationStatus() == 4) {
            BottomSheetUtil.showShopCheck(activity, App.INSTANCE.getString(R.string.libappCircleCheckUtil8), () -> {
                ARouter.getInstance().build(RConfig.MINE_SECURITY_CENTER).navigation();
            }).show();
            return false;
        }
        return true;
    }
}
